package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mall.annotation.OperationLog;
import com.mall.db.domain.Notice;
import com.mall.db.domain.Role;
import com.mall.db.service.NoticeService;
import com.mall.db.service.RoleService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system/nc")
public class NoticeController extends  BaseController<Notice>{

    @Resource(name="noticeService")
    private NoticeService ns;

    @Override
    public Map<String, Object> find(Notice n) {

        PageHelper.startPage(n.getPage(),n.getLimit());

        QueryWrapper<Notice> qw = new QueryWrapper<>();
        List<Notice> list = ns.list(qw);
        PageInfo<Notice> page = new PageInfo<>(list,n.getLimit());

        return this.findMap(page.getList(),page.getTotal());
    }

    @Override
    @OperationLog(value = "通知新增",type = 0)
    public Map<String, Object> add(Notice n) {
        boolean b = ns.save(n);
        return this.iud("新增",b,n);
    }

    @Override
    @OperationLog(value = "通知编辑",type = 0)
    public Map<String, Object> update(Notice n) {
        boolean b = ns.updateById(n);
        return this.iud("编辑",b,n);
    }
}
